package com.iflytek.day19;


import java.util.Calendar;

public class _04_CalendarDemo {
  public static void main(String[] args) {
    // 1.获取一个GregorianCalendar对象
    Calendar instance = Calendar.getInstance();// 获取子类对象

    // 2.打印子类对象
    System.out.println(instance);

    // 3.获取属性
    int year = instance.get(Calendar.YEAR);
    int month = instance.get(Calendar.MONTH) + 1;// Calendar的月份值是0-11
    int day = instance.get(Calendar.DAY_OF_MONTH);

    int hour = instance.get(Calendar.HOUR);
    int minute = instance.get(Calendar.MINUTE);
    int second = instance.get(Calendar.SECOND);

    int week = instance.get(Calendar.DAY_OF_WEEK);// 返回值范围：1--7，分别表示："星期日","星期一","星期二",...,"星期六"

    System.out.println(year + "年" + month + "月" + day + "日" +
            hour + ":" + minute + ":" + second);
    System.out.println(getWeek(week));

  }

  // 查表法，查询星期几
  public static String getWeek(int w) {// w = 1 --- 7
    // 做一个表(数组)
    String[] weekArray = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    // 索引  [0] [1]  [2] [3]  [4]  [5]  [6]
    // 查表
    return weekArray[w - 1];
  }
}
